window.addEventListener("load", () => {
    const submitBtn = document.querySelector("button")
    const form = document.querySelector("form")
    
    submitBtn.addEventListener("click", (e) => {
        e.preventDefault()
        console.log("表单提交被阻止,使用AJAX方式提交")
        
        // 在点击事件内部创建FormData并发送请求
        const formData = new FormData(form)
        fetch('http://172.18.214.70:8080/login', {
            method: "post",
            body: formData
        })
        .then(response => {
            if(!response.ok){
                throw new Error(`HTTP error! status: ${response.status}`)
            }
            return response.text()
        })
        .then(data => {
            console.log("输出", data)
        })
        .catch(error => {
            console.error('请求失败：', error)
        })
    })
})